package cn.jilian.dao.support;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.ResultSetSupportingSqlParameter;
import org.springframework.jdbc.core.RowMapper;


public class JdbcTemplateUsingUpperCaseKey extends JdbcTemplate {
	
	protected Map<String, Object> processResultSet(ResultSet rs, ResultSetSupportingSqlParameter param)
			throws SQLException {

		if (rs == null) {
			return Collections.emptyMap();
		}

		Map<String,Object> returnedResults1=super.processResultSet(rs,param);

		Map<String, Object> returnedResults = new HashMap<String, Object>();
		for(Map.Entry<String, Object> e:returnedResults1.entrySet()) {
			returnedResults1.put(StringUtils.upperCase(e.getKey()), e.getValue());
		}
		return returnedResults;
	}
	
	protected RowMapper<Map<String, Object>> getColumnMapRowMapper() {
		return new UpperCaseColumnMapRowMapper();
	}
}
